package test3.main;

import test3.bean.Admini;
import test3.controller.PageController;
import test3.controller.impl.PageControllerImpl;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

public class AddAdminAction implements ActionListener {

	Index index;
	
	public AddAdminAction(Index in) {
		index = in;
	}

	private PageController controller=new PageControllerImpl();
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String select = e.getActionCommand();
		if(select == "Register") {

			String usernme=index.addAdminIdText.getText();
			String password=index.addAdminPasswordText.getText();

			if (usernme!=null&& password!=null) {

				Admini admini = new Admini(usernme, password);

				System.out.println(admini);

				controller.addAdmir(admini);

				Toolkit.getDefaultToolkit().beep();
				JOptionPane.showMessageDialog(null, "Add success",
						"Result", JOptionPane.PLAIN_MESSAGE);
			}else {
				JOptionPane.showMessageDialog(null, "请输入管理员信息",
						"Result", JOptionPane.PLAIN_MESSAGE);
			}
		}
		else {
			index.card.show(index.panel, "welcome");
		}
	}

}
